<template>
  <div>
    <h1>订单已完成，感谢您的信任</h1>
    <div class="mainbox">
      <el-row>
        <el-col :span="8">
          <span style="margin-right: 10px">如实描述</span>
          <el-rate
            v-model="valuerushimiaoshu"
            allow-half
            size="large"
            class="icon"
          />
        </el-col>
        <el-col :span="8">
          <span style="margin-right: 10px">位置便利</span>
          <el-rate
            v-model="valueweizhibianli"
            allow-half
            size="large"
            class="icon"
          />
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <span style="margin-right: 10px">干净卫生</span>
          <el-rate
            v-model="valueganjingweisheng"
            allow-half
            size="large"
            class="icon"
          />
        </el-col>
        <el-col :span="8">
          <span style="margin-right: 10px">高性价比</span>
          <el-rate
            v-model="valuegaoxingjiabi"
            allow-half
            size="large"
            class="icon"
          />
        </el-col>
      </el-row>
      <el-row class="contextbox">
        <el-col :span="24">
          <el-form :model="form" label-width="120px">
            <el-form-item label="评论文字">
              <el-input v-model="form.desc" type="textarea" />
            </el-form-item>
          </el-form>
          <el-button type="primary" round @click="conponent"
            >完成评价</el-button
          >
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script setup>
import { onMounted, getCurrentInstance, ref, reactive } from "vue";
import { useRoute, useRouter } from "vue-router";
import { ElMessage } from "element-plus";
let router = useRouter();
let route = useRoute();
let index = route.query.index;
let hid=route.query.hid;
let { proxy } = getCurrentInstance();
let valuerushimiaoshu = ref(0);
let valueweizhibianli = ref(0);
let valueganjingweisheng = ref(0);
let valuegaoxingjiabi = ref(0);
let form = reactive({
  desc: "",
});
let tocode=undefined;
let conponent =async () => {
  if (
    !valuerushimiaoshu.value ||
    !valueweizhibianli.value ||
    !valueganjingweisheng.value ||
    !valuegaoxingjiabi.value
  ) {
    ElMessage.error("请评价选项分数");
  }else{
    // let token=localStorage.getItem('token');
    let token=15;
    let time=new Date().toLocaleDateString();
    let obj = {
    factualaccounts: valuerushimiaoshu.value,
    convenientlocation: valueweizhibianli.value,
    clean: valueganjingweisheng.value,
    higher: valuegaoxingjiabi.value,
    eavcontext: form.desc,
    createdtime:time,
    token,
    hid
  };
  console.log(obj)
  console.log(typeof obj.eavcontext)
  let res=await proxy.$axios('/pinglunsumbit',{params:obj});
//   console.log(res.data);
  tocode=res.data.info;
  }
  if(tocode){
    if(tocode==1989){
    router.push(`/notice?index=${index}`);
  }else{
    ElMessage.error("未完成评价，请完成评价");
  }
  }
};
</script>

<style lang='scss' scoped>
.mainbox {
  width: 70%;
  margin: 50px auto;
  .contextbox {
    margin-left: -50px;
  }
}
</style>